#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

char* getCard(int cardNo);

int main() {
    int i; //loop counter
    int r; //initialization variable
    int a; //testing variable for empty pile
    int b; //testing variable for empty pile
    int bonus = 0; //placeholder for bonus
    int partialPass = 1; //for compound tests
    int failcount = 0; //track tests passed
    int passcount = 0; //track tests failed
    int check; //holds result returned from test function
    int seed = 1000;
    int numPlayer = 2;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    
    /*
     * test that playing council_room makes player draw 4 and discard 1 for
     * a net gain of 3, and that opposing player draws 1 card.
     * 
     */

    printf("\nTesting great_hall card:\n\n");

    for (i = 0; i < numPlayer; i++){

        printf("Testing great_hall card played by player %d:\n", i);
        memset(&G, 23, sizeof(struct gameState));   // clear the game state
        r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
        
        //check for empty hand
        if (G.handCount[i] == 0){
            G.handCount[i] = 1;
        }

        G.hand[i][0] = great_hall; //put great_hall @ position 1
        G.whoseTurn = i; //set turn to current player


        a = G.handCount[i];
        b = G.numActions;        

        check = cardEffect(great_hall, -1, -1, -1, &G, handCard(0, &G), &bonus);

        printf("playing great_hall set player %d's handcount to %d, ",
        i, G.handCount[i]);
        printf("Expected: %d\n", a);

        printf("playing great_hall set numActions to %d, ", G.numActions);
        printf("Expected: %d\n", b + 1);
        
        printf("cardEffect() returned %d after playing great_hall", check);
        printf(", Expected: 0\n");

        if(G.handCount[i] != a){
            partialPass = 0;
        }          
        if(G.numActions != b + 1){
            partialPass = 0;
        }        
        if(check != 0){
            partialPass = 0;
        }
        if (partialPass == 1) {
            printf("TEST PASSED\n\n");
            passcount++;
        }
        else{
            printf("TEST FAILED\n\n");
            failcount++;
        }
    }

    if (failcount == 0){
        printf("All tests passed!\n\n");
    }
    else{
        printf("%d tests failed. %d tests passed.\n", failcount, passcount);
        printf("Review log above for details.\n\n");
    }
    return 0;
}



